package com.karolak.stock.strategy;

import java.util.ArrayList;
import java.util.List;

import com.karolak.stock.indicator.EmaInd;
import com.karolak.stock.indicator.FftInd;
import com.karolak.stock.indicator.HighInd;
import com.karolak.stock.indicator.HorizontalInd;
import com.karolak.stock.indicator.Indicator;
import com.karolak.stock.indicator.LowInd;
import com.karolak.stock.indicator.SumInd;
import com.karolak.stock.oscilator.DeltaOsc;
import com.karolak.stock.oscilator.DiffOsc;
import com.karolak.stock.oscilator.Oscilator;

public class CompStrategy extends Strategy {


	protected String defineConfig() {
		return "{signalThreshold:0.0003,votingThreshold:0.7}";
	}

	@Override
	protected List<Indicator> defineVoters() {
		
		String chBase = "base";
		String chDelta = "delta";
		String chDiff = "diff";
		
		List<Indicator> voters = new ArrayList<Indicator>();
		
		Indicator price = getDataManager().addSeries(new Indicator("Price", getDataManager()), chBase);
		Indicator emaf = null;
		for (int p : getConfig().getPeriods()) {
			
			Indicator ema = getDataManager().addSeries(new EmaInd(getDataManager(), p, price), chBase);
			if (emaf == null) {
				emaf = price;
			}

			DiffOsc diffEma =  getDataManager().addSeries(new DiffOsc( getDataManager(), p, emaf, ema )/*, chDelta*/);
			voters.add(diffEma);
			emaf = ema;			
			
			Indicator low = getDataManager().addSeries(new LowInd(getDataManager(), p, price), chBase);
			Indicator high = getDataManager().addSeries(new HighInd(getDataManager(), p, price), chBase);

			DiffOsc diffDown = getDataManager().addSeries(new DiffOsc(getDataManager(), p, price, high)/*, chDiff*/);
			DiffOsc diffUp = getDataManager().addSeries(new DiffOsc(getDataManager(), p, price, low)/*, chDiff*/);
			SumInd trend = getDataManager().addSeries(new SumInd(getDataManager(), diffDown, diffUp));
			Indicator ema2 = getDataManager().addSeries(new EmaInd(getDataManager(), p, trend)/*, chDiff*/);
			
			voters.add(trend);
			voters.add(ema2);
		}
		return voters;
	}
	
	public void tempLookup() {
		String chBase = "base";
		String chDelta = "delta";
		String chDiff = "diff";
		
		Indicator price = getDataManager().addSeries(new Indicator("Price", getDataManager()), chBase);
//		Indicator low = addSeries(new LowInd(this, period, price), chBase);
//		Indicator high = addSeries(new HighInd(this, period, price), chBase);
//		Indicator ema = addSeries(new EmaInd(this, period, price), chBase);
//		Indicator ema = addSeries(new EmaInd(this, periodFft, price), chBase);
//		Indicator ema5p = addSeries(new EmaInd(this, period5, price), chBase);
//		Indicator ema25p = addSeries(new EmaInd(this, period25, price), chBase);
//		Indicator fft = addSeries(new FftInd(this, periodFft, price, harmonicCount), chBase);
		Indicator fft2 = getDataManager().addSeries(new FftInd(getDataManager(), getConfig().getFftPeriod(), price, 2), chBase);
//		Indicator fft3 = addSeries(new FftInd(this, periodFft, price, 3), chBase);
//		Indicator fft10 = addSeries(new FftInd(this, periodFft, price, 2), chBase);
		

		HorizontalInd h1 = getDataManager().addSeries(new HorizontalInd(getConfig().getSignalThreshold()), chDelta);
		HorizontalInd h2 = getDataManager().addSeries(new HorizontalInd(-getConfig().getSignalThreshold()), chDelta);
//		DeltaOsc delPrice = addSeries(new DeltaOsc(this, price, period, getThreshold()), chDelta);
//		DeltaOsc delEma = addSeries(new DeltaOsc(this, ema, periodFft, getThreshold()), chDelta);
//		DeltaOsc delEma5 = addSeries(new DeltaOsc(this, ema5p, periodFft, getThreshold()), chDelta);
//		DeltaOsc delEma25 = addSeries(new DeltaOsc(this, ema25p, periodFft, getThreshold()), chDelta);
		
		DiffOsc diffFft2 = getDataManager().addSeries(new DiffOsc(getDataManager(), getConfig().getFftPeriod(), price, fft2), chDelta);
		
		DeltaOsc delFft2 = getDataManager().addSeries(new DeltaOsc(getDataManager(), fft2, getConfig().getFftPeriod(), getConfig().getSignalThreshold()), chDelta);

		
		Oscilator[] voters = {
//				delPrice, 
//				delEma, 
//				delEma5, 
//				delEma25,
				diffFft2,
				delFft2
		};
		Voter voter = getDataManager().addSeries(new Voter("v", getDataManager(), -1, getConfig().getSignalThreshold(),  getConfig().getVotingThreshold(), voters), "v");
		Collector collector = getDataManager().addSeries(new Collector("c", getDataManager(), -1, voter), "c");

		
		
//		Formula sgPrice = addSignal(price, getPeriod(), getThreshold(), null);
//
//		Formula ema4 = addSeries(new EmaInd(4), null);
//		Formula ema16 = addSeries(new EmaInd(16), null);
//		Formula ema32 = addSeries(new EmaInd(32), chBase);
//		Formula ema64 = addSeries(new EmaInd(64), null);
//		Formula ema128 = addSeries(new EmaInd(128), null);
//
//		addSignal(ema4, getPeriod(), getThreshold(), null);
//		addSignal(ema16, getPeriod(), getThreshold(), null);
//		addSignal(ema32, getPeriod(), getThreshold(), null);
//		addSignal(ema64, getPeriod(), getThreshold(), null);
//		addSignal(ema128, getPeriod(), getThreshold(), null);
//
//		Formula diffEma16Ema4 = addDiff(getPeriod(), ema16, ema4, null);
//		Formula diffEma32Ema4 = addDiff(getPeriod(), ema32, ema4, chDiff);
//		Formula diffEma32Ema16 = addDiff(getPeriod(), ema32, ema16, null);
//		Formula diffEma64Ema16 = addDiff(getPeriod(), ema64, ema16, null);
//
//		addSignal(diffEma16Ema4, getPeriod(), getThreshold(), null);
//		addSignal(diffEma32Ema4, getPeriod(), getThreshold(), null);
//		addSignal(diffEma32Ema16, getPeriod(), getThreshold(), null);
//		addSignal(diffEma64Ema16, getPeriod(), getThreshold(), null);
//
//		Formula delDiffEma16Ema4 = addDelta(diffEma16Ema4, getPeriod(), getPeriod(), null);
//		Formula delDiffEma32Ema4 = addDelta(diffEma32Ema4, getPeriod(), getPeriod(), chDelta);
//		Formula delDiffEma32Ema16 = addDelta(diffEma32Ema16, getPeriod(), getPeriod(), null);
//		Formula delDiffEma64Ema16 = addDelta(diffEma64Ema16, getPeriod(), getPeriod(), null);
//
//		addSignal(delDiffEma16Ema4, getPeriod(), getThreshold(), chSignal);
//		addSignal(delDiffEma32Ema4, getPeriod(), getThreshold(), chSignal);
//		addSignal(delDiffEma32Ema16, getPeriod(), getThreshold(), chSignal);
//		addSignal(delDiffEma64Ema16, getPeriod(), getThreshold(), chSignal);
//
//		Formula fft1 = addSeries(new Fft(this, getFftPeriod(), 1, price.getName()), null);
//		Formula fft2 = addSeries(new Fft(this, getFftPeriod(), 2, price.getName()), null);
//		Formula fft3 = addSeries(new Fft(this, getFftPeriod(), 3, price.getName()), null);
//
//		addSignal(fft1, getPeriod(), getThreshold(), null);
//		addSignal(fft2, getPeriod(), getThreshold(), null);
//		addSignal(fft3, getPeriod(), getThreshold(), null);
//
//		Formula diffFft1Fft2 = addDiff(getPeriod(), fft1, fft2, null);
//		Formula diffFft1Fft3 = addDiff(getPeriod(), fft1, fft3, null);
//
//		addSignal(diffFft1Fft2, getPeriod(), getThreshold(), null);
//		addSignal(diffFft1Fft3, getPeriod(), getThreshold(), null);
//
//		Formula highTr = addSeries(new HighTrInd(this, price.getName(), getPeriod()), null);
//		Formula lowTr = addSeries(new LowTrInd(this, price.getName(), getPeriod()), null);
//
//		Formula diffDropTr = addDiff("DropTr", getPeriod(), highTr, price, null);
//		Formula diffRiseTr = addDiff("RiseTr", getPeriod(), lowTr, price, null);
//		Formula sumTr = addSum("SumTr", getPeriod(), diffDropTr, diffRiseTr, null);
//
//		addSignal(sumTr, getPeriod(), getThreshold(), null);

		// chSignal
	}
}
